#!/bin/sh

package='nato-rto-latex'

set -e

if test $# -ne 1; then
  echo "usage: $0 VERSION"
  exit 1
fi

version=$1

if ! echo $version | grep -E "^[0-9]+\.[0-9]+\.[0-9]+$"
then
  echo "VERSION should be of the form 1.2.5 (major.minor.revision)"
  exit 1
fi

if ! grep -q $version nato-rto.cls
then
  echo "Error: version skew. '$version' does not match that in class"
  grep -H ProvidesClass nato-rto.cls
  exit 1
fi

date=`date +%Y/%m/%d`

if ! grep -q $date nato-rto.cls
then
  echo "Error: date skew. '$date' does not match that in class"
  grep -H ProvidesClass nato-rto.cls
  exit 1
fi 

# Refresh sample document

pdflatex sample >  refresh-sample.log
bibtex   sample >> refresh-sample.log
pdflatex sample >> refresh-sample.log
pdflatex sample >> refresh-sample.log
rm sample.{bbl,blg,aux,out,log} refresh-sample.log
mv sample.pdf sample-eg.pdf

# Make bundles

mkdir $package-$version
cp `cat Manifest.txt` $package-$version
tar zcf $package-$version.tgz $package-$version
zip -rq $package-$version.zip $package-$version
rm -rf $package-$version

cat << MESSAGE

`openssl dgst -sha1 $package-$version.tgz`

Don't forget to tag,

 svn cp -m'To tag release $version.' \\
   https://$package.googlecode.com/svn/trunk \\
   https://$package.googlecode.com/svn/tags/rel_$version

and upload,

 http://code.google.com/p/$package/downloads/list
 http://ctan.org/upload

MESSAGE
